package castledefense.game.render;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import castledefense.data.BuildingData;
import castledefense.data.Resources;
import castledefense.logic.Map;
import castledefense.logic.buildings.Building;

final public class RenderBuilding {

	public static void draw(Map map, SpriteBatch batch) {
		// Draw buildings

		final ArrayList<Building> list = map.getConstructionList();
		final int size = list.size();
		for (int i = 0; i < size; i++) {
			final Building tmp = list.get(i);
			final int drawSize = Map.cellWidth *tmp.getSize();
			batch.draw(Resources.buildingPlatform, tmp.getRenderingX(), tmp.getRenderingY(),drawSize,drawSize);
		}

		final ArrayList<Building> buildingList = map.getBuildingList();
		final int size2 = buildingList.size();

		for (int i = 0; i < size2; i++) {
			final Building tmp = buildingList.get(i);
			final int type = tmp.getBuildingType();
			final int elementType = tmp.getElementType();
			// draw the right texture that getTexture method choose
			final int drawSize = tmp.getSize() * Map.cellWidth;
			batch.draw(BuildingData.getTexture(type, elementType), tmp.getRenderingX(),
					tmp.getRenderingY());
			// if current building is selected.
			if (tmp.getIsSelected()) {
				batch.draw(Resources.selectedIm, tmp.getRenderingX(), tmp.getRenderingY(),
						drawSize, drawSize);
			}
		}

	}
}